import { instance } from '../request'

const request = instance

/**
 * 资源批量上传
 * @param resources 资源列表
 * @param projectId  项目id
 * @param groupId  分组id
 * @returns
 */
export const uploadResourcesApi = (
  resources: any,
  projectId: string,
  groupId?: string
): PromiseRes =>
  request.post(
    `/resource/upload?projectId=${projectId}&groupId=${groupId}`,
    resources,
    { headers: { 'Content-Type': 'multipart/form-data' } }
  )

/**
 * 修改资源分组
 * @param resourceId 资源id
 * @param projectId 项目id
 * @param groupId 分组id
 * @returns
 */
export const changeResourceGroupApi = (
  resourceId: string,
  projectId: string,
  groupId?: string
): PromiseRes =>
  request.post(
    `/resource/changeResourceGroup/${resourceId}?projectId=${projectId}&groupId=${groupId}`
  )

/**
 * 批量删除资源
 * @param resourceIds 资源 id 列表
 * @returns
 */
export const deleteResourcesApi = (resourceIds: string[]): PromiseRes =>
  request.post(`/resource/deleteResources`, resourceIds)

/**
 *分页获取资源列表
 * @param size 分页大小
 * @param page 分页页码
 * @param projectId 项目id
 * @param groupId  分组id
 * @returns
 */
export const getResourcesApi = (
  size: number,
  page: number,
  projectId: string,
  groupId: string
): PromiseRes<QueryResourceListItf> =>
  request.get(
    `/resource/resourceList/${projectId}?size=${size}&page=${page}&groupId=${groupId}`
  )

/**
 * 获取删除资源列表
 * @param size 分页大小
 * @param page 分页页码
 * @returns
 */
export const getDeleteResourcesApi = (
  size: number,
  page: number
): PromiseRes<QueryResourceListItf> =>
  request.get(`/resource/getDeleteResources?size=${size}&page=${page}`)

/**
 *批量恢复资源
 * @param resourceIds 要恢复的资源 id 列表
 * @returns
 */
export const recoverResourcesApi = (resourceIds: string[]): PromiseRes =>
  request.post(`/resource/recoverResources`, resourceIds)
